package com.content.view.Frame.MainPanel.MPHome
{
	import com.content.model.Collection.ItemGroup;
	import com.content.model.LoadedAssets.SkinProxy;
	import com.content.model.OnlineRes.NoticeVO;
	import com.content.view.Frame.MainPanel.SPBase;
	import com.library.core.IDisposable;
	import com.library.core.UIObject;
	
	import flash.display.Sprite;
	
	public class SPNotice extends SPBase
	{
		private var _logo:Sprite;
		private var _noticeContainer:Sprite;
		
		public function SPNotice()
		{
			super(this);
			
			_logo = new SkinProxy.IMG_MPHome_NoticeLogo() as Sprite;
			addChild(_logo);
			
			_noticeContainer = new Sprite();
			addChild(_noticeContainer);
		}
		
		private function RemoveAllItem():void{
			var nItem:NoticeItem;
			while(_noticeContainer.numChildren > 0){
				nItem = _noticeContainer.removeChildAt(0) as NoticeItem;
				nItem.Dispose();
			}
		}
		
		override public function SetLayout(areaWidth:int, areaHeight:int):void{
			super.SetLayout(areaWidth, areaHeight);
			
			_logo.x = 50;
			_logo.y = 10;
			_noticeContainer.x = 10;
			_noticeContainer.y = int(_logo.y + _logo.height + 15);
			
			var nItem:NoticeItem;
			for(var i:uint = 0; i < _noticeContainer.numChildren; i++){
				nItem = _noticeContainer.getChildAt(i) as NoticeItem;
				nItem.SetLayout(areaWidth - 20);
			}
		}
		
		/* Public Method
		* ---------------------------------------------------------- */
		public function Refresh(itemGroup:ItemGroup):void{
			RemoveAllItem();
			
			var insertY:int = 0;
			var itemVO:NoticeVO;
			for(var i:uint = 0; i < itemGroup.Length; i++){
				itemVO = itemGroup.Items[i] as NoticeVO;
				
				var nItem:NoticeItem = new NoticeItem(itemVO);				
				_noticeContainer.addChild(nItem);
				nItem.y = insertY;
				insertY += 22;
			}
			
			SetLayout(_areaW, _areaH);	// 得到数据后，手动重排内容
		}
		
		override public function Dispose():void
		{
		}
	}
}